package cn.ly.array;

public class HighArray {
	
	private long[] a;
	private int nElems;//有效元素个数
	
	public HighArray(int max){
		a = new long[max];
		nElems = 0;
	}
	
	
	
	//查找
	public boolean find(long searchKey){
		int i = 0;
		for(; i < this.nElems; i++){
			if(a[i] == searchKey){
				break;
			}
		}
		if(i == this.nElems){
			return false;
		}
		return true;
	}
	//插入
	public void insert(long value){
		a[this.nElems] = value;
		this.nElems++;
	}
	
	public boolean delete(short value){
		System.out.println("short=="+value);
		return false;
	}
	
	//删除
	public boolean delete(long value){
		int i = 0;
		for(; i < this.nElems; i++){
			if(a[i] == value){
				break;
			}
		}
		if(i == this.nElems){
			//System.out.println("Can't find");
			return false;
		}
		for(; i < this.nElems; i++){
			a[i] = a[i++];
		}
		this.nElems--;
		return true;
	}
	
	//删除
	public boolean delete(int index){
		System.out.println("=="+index);
		if(index >= this.nElems){
			return false;
		}
		for(int i=index; i < nElems; i++){
			a[i] = a[i+1];
		}
		this.nElems--;
		return true;
	}
	
	//查看所有
	public void display(){
		for(int j = 0; j < nElems; j++){
			System.out.print(a[j] + " ");
		}
	}

}
